﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Ue.CQRS.Samples.Domain.Models
{
    public abstract class EntityBase
    {
        private Lazy<Guid> lazyIdentity;

        public EntityBase() : 
            this(new Guid()) { }

        public EntityBase(Guid id)
        {
            this.lazyIdentity = id.Equals(new Guid())
            ? new Lazy<Guid>(() => EntityBase.GetNewId())
            : new Lazy<Guid>(() => id);
        }

        public Guid Id 
        { 
            get { return this.lazyIdentity.Value; } 
        }

        public static Guid GetNewId()
        {
            return Guid.NewGuid();
        }
    }
}